//
//  MQStatusToolBar.swift
//  SinaWeiBo
//
//  Created by 毛强 on 16/1/20.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class MQStatusToolBar: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    var statusViewModel:MQStatusViewModel?{
        didSet{
            leftBtn.setTitle(statusViewModel?.repostsCount, forState: UIControlState.Normal)
            midBtn.setTitle(statusViewModel?.commentsCount, forState: UIControlState.Normal)
            rightBtn.setTitle(statusViewModel?.attitudesCount, forState: UIControlState.Normal)
        }
    }
    
    private var leftBtn:UIButton!
    private var midBtn:UIButton!
    private var rightBtn:UIButton!
    
    private func setupUI(){
//        backgroundColor = RandomColor()
        leftBtn = addChildBtn("转发", imageName: "timeline_icon_retweet")
        midBtn = addChildBtn("评论", imageName: "timeline_icon_comment")
        rightBtn = addChildBtn("赞", imageName: "timeline_icon_unlike")
        
        let sp1 = splitsView()
        let sp2 = splitsView()
        
        //设置约束
        leftBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(midBtn.snp_width)
        }
        midBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(leftBtn.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(rightBtn.snp_width)
        }
        rightBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(midBtn.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.trailing.equalTo(self)
        }
        
        sp1.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(leftBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
        sp2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(midBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
    }
    
    //btn
    private func addChildBtn(title:String, imageName:String) -> UIButton{
        let btn = UIButton(textColor: UIColor.darkGrayColor(), fontSize: 15)
        btn.setTitle(title, forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        addSubview(btn)
        return btn
    }
    
    //splite
    private func splitsView() ->UIImageView {
        let splitsView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
        addSubview(splitsView)
        return splitsView
    }
}
